const DEFAULT_PAGE = 0;
//获取应用实例
const app = getApp()
// 云调用
const db = wx.cloud.database()
Page({
  data: {
    // 屏幕移动量数组
    toView: `card_${DEFAULT_PAGE}`,
    list: [],
    Modelcard: '',
    //动态Tab
    title: ['主页', '发现'],
    active: 0,
    index: 0,
    logo: 'https://636c-cloud2-9gomot6xb9909364-1305292962.tcb.qcloud.la/%E8%93%9D%E5%A4%A9%E7%A7%91%E6%99%AE3.0%E5%AD%98%E5%82%A8/index/Logo.png?sign=f265df88381fa0907b75e467357c8b9e&t=1646620340',
  },
  onLoad: function (e) {
    //云开发调用
    db.collection('Modelcard').where({
        _openid: 'user01'
      })
      .get({
        success: res => {
          // res.data 是包含以上定义的两条记录的数组
          this.setData({
            Modelcard: res.data,
          })
        }
      })
  },
  setchange: function (o) {
    let activeID = o.currentTarget.dataset.index
    //console.log(activeID)
    this.setData({
      active: activeID,
    })
  },
  touchStart(e) {
    this.startPageX = e.changedTouches[0].pageX;
  },
  startPageX: 0,
  currentView: DEFAULT_PAGE,
  touchEnd(e) {
    const moveX = e.changedTouches[0].pageX - this.startPageX;
    const maxPage = this.data.list.length - 1;
    if (Math.abs(moveX) >= 100) {
      if (moveX > 0) {
        this.currentView = this.currentView !== 0 ? this.currentView - 1 : 0;
      } else {
        this.currentView = this.currentView !== maxPage ? this.currentView + 1 : maxPage;
      }
    }
    this.setData({
      toView: `card_${this.currentView}`
    });
  },
})